package com.shigen.springcloud.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder.Builder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 路由配置的代码编写
 *
 * @author shigenfu
 * @date 2022/7/2 4:29 下午
 */
@Configuration
public class GateWayConfig {

  @Bean
  public RouteLocator customRouteLocator(RouteLocatorBuilder routeLocatorBuilder) {
    // http://news.baidu.com/guonei
    Builder routes = routeLocatorBuilder.routes();
    routes.route("path_route",
        r -> r.path("/guonei")
            .uri("http://news.baidu.com/guonei")).build();
    return routes.build();
  }

  @Bean
  public RouteLocator customRouteLocator2(RouteLocatorBuilder routeLocatorBuilder) {
    // http://news.baidu.com/guoji
    Builder routes = routeLocatorBuilder.routes();
    routes.route("path_route2",
        r -> r.path("/guoji")
            .uri("http://news.baidu.com/guoji")).build();
    return routes.build();
  }
}
